﻿using B.S.BasicData.ErrorCode;
using B.S.BasicData.Write.Application.Common.Role;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.BasicData.Write.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class RoleController : ControllerBase
    {
        private readonly IMediator mediator;

        public RoleController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 添加角色信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<ApiResult<int>> CreateRoleHandle(CreateRoleCommon request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 修改角色信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<ApiResult<int>> UpdateRoleHandle(UpdateRoleCommon request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 逻辑删除角色信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<ApiResult<int>> DelRoleHandle(DelRoleCommon request)
        {
            return mediator.Send(request);
        }

         /// <summary>
         /// 通过部门给用户分配角色 
         /// </summary>
         /// <param name="request"></param>
         /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> DelparmentRoleHandle(DelparmentRoleCommon request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 删除角色中的用户
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> DelRoleaccountnameHandle(DelRoleaccountnameCommon request)
        {
            return await mediator.Send(request);
        }


        }
}
